package com.dtx.iterator.myself;

import com.dtx.iterator.gongyongde.Book;
import com.dtx.iterator.gongyongde.Iterator;


public class MyBookShelfIterator implements Iterator {

    private MyBookShelf myBookShelf;

    private int index;

    public MyBookShelfIterator(MyBookShelf myBookShelf) {
        this.myBookShelf = myBookShelf;
        this.index = 0;
    }


    @Override
    public boolean hasNext() {
        if (index<myBookShelf.getLength()){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Object next() {
        Book book = myBookShelf.getBookAt(index);
        index++;
        return book;
    }
}
